package com.sky.task;

import com.alibaba.fastjson.JSON;
import com.sky.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Component
public class WebSocketTask {
    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * 通过WebSocket每隔5秒向客户端发送消息
     */
//    @Scheduled(fixedRate = 5000)
    public void sendMessageToClient() {
        //通过websocket通知客户端订单支付成功
        Map map = new HashMap();
        map.put("type", 1); //1.来了订单提醒  2.催单提醒
        map.put("orderId",1);
        map.put("content","来新订单了："+123456789);

        String json = JSON.toJSONString(map);
        webSocketServer.sendToAllClient(json);
    }
}
